/**
 * 
 */
package com.nari.heatassist.utils;

/**
 * 耗热分析报表生成工具
 * @author Xiaopeng
 * @date 2014-4-28
 */
public class ConsumeStatisReportUtil {
	
	/**
	 * 报表XML生成工具
	 * @param caption 报表主标题(必选项)
	 * @param subcaption 报表副标题(可选项)
	 * @param xAxisName X轴坐标名称(必选项)
	 * @param yAxisName Y轴坐标名称(必选项)
	 * @param reportData 报表数据(可选项)
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-4-28
	 */
	public static String genReportChartXml(String caption, String subcaption, String xAxisName,
			String yAxisName, String reportData) {
		StringBuffer chartData = new StringBuffer("<chart ");
		//标题
		chartData.append("caption='");
		chartData.append(caption);
		chartData.append("' ");
		//副标题
		if(subcaption!=null && !"".equals(subcaption)) {
			chartData.append("subcaption='(");
			chartData.append(subcaption);
			chartData.append(")' ");
		}
		//轴坐标名称设置
		chartData.append("xAxisName='" + xAxisName + "' ");
		chartData.append("PYAxisName='" + yAxisName + "' ");
		chartData.append("yAxisName='" + yAxisName + "' ");
		//右键菜单设置
		chartData.append("showAboutMenuItem='0' showPrintMenuItem='1' unescapeLinks='0' ");
		chartData.append("exportEnabled='1' exportAtClient='1' exportHandler='fcExporter1' exportDialogMessage='正在生成,请稍候...' exportFormats='PNG=生成PNG图片|JPG=生成JPG图片|PDF=生成PDF文件' ");
		//字体样式
		chartData.append("baseFontSize='11' ");
		//折线样式
		chartData.append("lineThickness='3' anchorRadius='3' showValues='1' formatNumberScale='0' ");
		//坐标轴样式设置
		chartData.append("decimals='3' divLineAlpha='20' divLineColor='CC3300' ");
		chartData.append("divLineIsDashed='1' showAlternateHGridColor='1' alternateHGridAlpha='5' ");
		//坐标区域样式设置
		chartData.append("alternateHGridColor='CC3300' shadowAlpha='40' labelStep='1' ");
		chartData.append("numvdivlines='20' chartRightMargin='35' bgColor='FFFFFF,FFF0FF' ");
		//图例设置
		chartData.append("showLegend='1' interactiveLegend='1' legendBorderThickness='1' legendShadow='1' legendPosition='BOTTOM' legendAllowDrag='0' ");
		//设置动画效果
		chartData.append("useRoundEdges='1' animation='1'>");
		//报表数据，包括<categories>、<dataset>、<set>数据项
		if(reportData!=null && !"".equals(reportData)) {
			chartData.append(reportData);
		}
		//图表样式
		chartData.append("<styles>");
		chartData.append("<definition>");
		chartData.append("<style name='Anim1' type='animation' param='_xscale' start='0' duration='1'/>");
		chartData.append("<style name='Anim2' type='animation' param='_alpha' start='0' duration='0.6'/>");
		chartData.append("<style name='DataShadow' type='Shadow' alpha='40'/>");
		chartData.append("</definition>");
		chartData.append("<application>");
		chartData.append("<apply toObject='DIVLINES' styles='Anim1'/>");
		chartData.append("<apply toObject='HGRID' styles='Anim2'/>");
		chartData.append("<apply toObject='DATALABELS' styles='DataShadow,Anim2'/>");
		chartData.append("</application>");
		chartData.append("</styles>");
		chartData.append("</chart>");
		return chartData.toString();
	}
	
	/**
	 * 生成2D报表数据单元
	 * @param label
	 * @param value
	 * @return
	 * @author Xiaopeng
	 * @date 2014-4-28
	 */
	public static String gen2DReportData(String label, String value) {
		if(label!=null && value!=null) {
			return "<set label='"+label+"' value='"+value+"' />";
		}
		return "";
	}
}
